$(document).ready(function () {
	gzfw.onload();
})

var gzfw = (function () {
	var curPage = 0,
		pageSize = 6;
	var host = "http://zxhd.ha-n-tax.gov.cn";
	var www = "http://www.ha-n-tax.gov.cn";
	var curSeg;
	var init = function () {
		//页面高度
		$(function () {
			var window_h = $(window).height();
			var footer_h = $(".footer").height();
			$(".main").css("height", window_h - footer_h + "px");
			$(".ggfw_box").css("height", window_h - footer_h-3 + "px");
			$(".thir_content ul li:nth-child(5n)").css("margin-right","0px")
		});
		//切换通知公告
		$(".left-title").on("click", "li", function (e) {
			var $li = $(e.target);
			$(".left-title li").removeClass("active");
			$li.addClass("active");
			var i = $li.index();
			$(".news:eq(" + i + ")").css("z-index", "1000").siblings().css("z-index", "0");
			if(i=0){
       	 	 	curSeg.loadBZDS('3010301');
       	 	 }else if(i=3){
       	 	 	curSeg.loadBZDS('3011501');
       	 	 }
		})
	}

	return {
		onload: function () {
			init();
			curSeg = gzfw;
			curSeg.onQuery();
			curSeg.tabSwitch();

		},
        /*选项卡*/
       tabSwitch:function(){
       	 $(".ggfw_l li").click(function(){
       	 	 var n=$(this).index();
       	 	 $(this).addClass("active");
       	 	  $(this).siblings("li").removeClass("active");
       	 	 $(".ggfw_r").eq(n).show();
       	 	 $(".ggfw_r").eq(n).siblings(".ggfw_r").hide();
       	 	 if(n=0){
       	 	 	curSeg.loadBZDS('3010301');
       	 	 }else if(n=3){
       	 	 	curSeg.loadBZDS('3011501');
       	 	 }
       	 })
       },
		//更多跳转
		onMoreHref: function () {
			window.location = 'gsgg.html'
		},

		onQuery: function () {
			curSeg.loadBZDS('3010301');
		},

		loadBZDS: function (lm_id) {
			if (lm_id == "3010301") {
				$.ajax({
					url: host + "/cms/dfwj/getNRGL_DFWJQT.do?CURPAGE=1&PAGESIZE=6&LM_ID=3010301&DFWJ_FBZT=1&ORDERBY=FBRQ%20DESC&CUR_USERID=null",
					type: "GET",
					dataType: "jsonp", //指定服务器返回的数据类型
					jsonpCallback: "gzfw.onqueryCallback"
				})
			}else if(lm_id == "3011501"){
                $.ajax({
                	 url: host + "/comm/zcyh/getListContentByLMID.do",
                     type: "GET",
                     dataType: "jsonp", //指定服务器返回的数据类型
                     data: {
                        LM_ID: lm_id, CURPAGE: curPage, LMYS_ID: '201705181141592', WD_LDDM: "0", NVG: 2, XZQH_DM: 0,
                        PAGESIZE: pageSize
                    },
                     jsonpCallback: "gzfw.onqueryCallbackQsgg",
                     success: function (data) {
                     	console.log(data)
                         var result = JSON.stringify(data); //json对象转成字符串
                    }
                });
			}
		},
		onqueryCallback: function (jsonObj){
			var url = www + "/003/trans.html?url=/websites/comm/dfwj/dfwj_info.html?";
			var html = ''
			html += '<ul>';
			for (var i = 0; i < jsonObj.data.length; i++) {
				html += "<li><a href='" + url + "lm_id=" + jsonObj.data[i].LM_ID + "&dfwj_id=" + jsonObj.data[i].DFWJ_ID + "&ADJUST=_hd_frame_r' target='_blank'";
				html += "title='" + jsonObj.data[i].DFWJ_BT + "--[" + jsonObj.data[i].DFWJ_FBRQ + "]'>";
				html += "" + jsonObj.data[i].DFWJ_BT + "</a>";
				html += "<span class='date'>" + jsonObj.data[i].DFWJ_FBRQ + "</span>";
				html += "</li>";
			}

			html += '</ul>';

			$('.zcfgtz').html(html);
		},
		 onqueryCallbackQsgg: function (jsonObj) {
            var url = www + "/003/xxgk_301/ssgg_30115/qsgg_3011501/";
            if (jsonObj.data) {
                var d = jsonObj.data[0];
                $(".wxl_qsgg").html(d.retVal.replaceAll("href=\"", "href=\"" + url));
            } else {
                return;
            }
        }
		

	}
})();
String.prototype.replaceAll = function (reallyDo, replaceWith, ignoreCase) {
    if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
        return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith);
    } else {
        return this.replace(reallyDo, replaceWith);
    }
}